﻿-- Function: trgfnupdatepo_lineupdate()

-- DROP FUNCTION trgfnupdatepo_lineupdate();

CREATE OR REPLACE FUNCTION trgfnupdatepo_lineupdate()
  RETURNS trigger AS
'declare id1 integer;
begin
	if new.discount_percent<>old.discount_percent or new.price_subtotal2<>old.price_subtotal2 then                                    
		update purchase_order set line_update=True,
			amount_untaxed=(Select sum(price_subtotal2) from purchase_order_line where order_id=new.order_id)
		where id=new.order_id;
	end if;                                
return NULL;
end;'
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION trgfnupdatepo_lineupdate() OWNER TO openerp;
